package cn.codergege.demo.service

import cn.codergege.demo.dao.PersonRepository
import cn.codergege.demo.entity.Person
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.context.junit.jupiter.SpringExtension
import java.util.*

@ExtendWith(SpringExtension::class)
@SpringBootTest
@ActiveProfiles("test")
class PersonServiceTest {
    private val log = LoggerFactory.getLogger(this::class.java)
    @Autowired
    lateinit var personService: PersonService
    @Autowired
    lateinit var personRepository: PersonRepository

    @BeforeEach
    fun initH2() {
        val persons = listOf<Person>(
            Person(null,"codergege", 1, Date(), "codergege@163.com"),
            Person(null, "djh", 0, null, null)
        )
        personRepository.saveAll(persons)
    }

    @Test fun testFindPersons() {
        val persons = personService.findPersons("codergege")
        assertEquals(persons?.size, 1)
        persons?.forEach(::println)
    }
}
